package com.jfreer.blog.service;

import com.jfreer.blog.dao.ITestDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * User: landy
 * Date: 15/5/4
 * Time: 下午3:38
 */
@Service
public class TestService implements ITestService {
    public static final Random RANDOM = new Random();
    @Resource
    private ITestDao testDao;

    @Override
    public Object all() {
        return testDao.findList();
    }

    @Override
    public Object first() {
        return testDao.findFirst();
    }

    @Override
    public Object hello() {
        int delay = RANDOM.nextInt(5);
        try {
            TimeUnit.SECONDS.sleep(delay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return delay + "";
    }

    @Override
    public Object world() {
        return "world";
    }

    @Override
    public Object exception() {
        throw new RuntimeException("I am Exception!!!");
    }
}
